
function [success, frac] = performanceEvolution (subject, qtyTrials, sequenceSize, maleStart, femaleStart)



% qtyTrials=300;%20;
% sequenceSize=40;
% maleStart=22;%21;
% femaleStart=29;%30; 

filename=strcat('RAW_',subject);

file=fopen(filename); 
data=fread(file, [4+sequenceSize qtyTrials]);
fclose(file);


%total right
win=0;

%noise=zeros(qtyTrials,sequenceSize);
subsampleMaleStim=[];
subsampleMaleAns=[];
subsampleMaleRight=[];
subsampleMaleWrong=[];
subsampleFemaleStim=[];
subsampleFemaleAns=[];
subsampleFemaleRight=[];
subsampleFemaleWrong=[];
subsampleConfident=[];
subsampleNonconfident=[];


for i=1:qtyTrials
     
   
    noise(i,:)=(data(3:2+sequenceSize,i)-data(2,i))';
    
    
        if(data(2,i)==maleStart)
            subsampleMaleStim=[subsampleMaleStim; noise(i,:)]; 
            if(data(sequenceSize+3,i)==1)
                subsampleMaleRight=[subsampleMaleRight; noise(i,:)];
                win=win+1;
            else if(data(sequenceSize+3,i)==0)
                    subsampleMaleWrong=[subsampleMaleWrong; noise(i,:)];
                end
            end 
        else if(data(2,i)==femaleStart)
                subsampleFemaleStim=[subsampleFemaleStim; noise(i,:)];
                if(data(sequenceSize+3,i)==0)
                    subsampleFemaleRight=[subsampleFemaleRight; noise(i,:)];
                    win=win+1;
                else if(data(sequenceSize+3,i)==1)
                    subsampleFemaleWrong=[subsampleFemaleWrong; noise(i,:)];
                   end
                end
            end
        end
    
    if(data(sequenceSize+3,i)==1)
        subsampleMaleAns=[subsampleMaleAns; noise(i,:)]; 
    else if(data(sequenceSize+3,i)==0)
        subsampleFemaleAns=[subsampleFemaleAns; noise(i,:)];
        end
    end
        
    
    if(data(sequenceSize+4,i)==1)
        subsampleConfident=[subsampleConfident; noise(i,:)];
    else subsampleNonconfident=[subsampleNonconfident; noise(i,:)];
    end
    
    %if ((data(2,i)==maleStart && data(sequenceSize+3,i)==1) || (data(2,i)==femaleStart && data(sequenceSize+3,i)==0))
    %    win=win+1;
    %end
    success(i)=win/i;
       
   
end


frac=win/qtyTrials;
trials=1:qtyTrials;

plot(trials,success); %evolution of success
 
calibIndices=mean(data(3:2+sequenceSize,:));
calibAnswers=data(sequenceSize+3,:);
   
%hist(mean(noise').*data(sequenceSize+3,:)); % what is this?!
%plot(calibIndices,calibAnswers,'x'); %male or female answer as a function of stimulus



end

